home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / libg_261.zip / libg_261 / libio / iostream.info-2 (.txt) < prev    next >
GNU Info File  |  1994-10-24  |  19KB  |  365 lines

  1. This is Info file iostream.info, produced by Makeinfo-1.55 from the
  2. input file ./iostream.texi.
  3. START-INFO-DIR-ENTRY
  4. * iostream: (iostream).                    The C++ input/output facility.
  5. END-INFO-DIR-ENTRY
  6.    This file describes libio, the GNU library for C++ iostreams and C
  7. stdio.
  8.    libio includes software developed by the University of California,
  9. Berkeley.
  10.    Copyright (C) 1993 Free Software Foundation, Inc.
  11.    Permission is granted to make and distribute verbatim copies of this
  12. manual provided the copyright notice and this permission notice are
  13. preserved on all copies.
  14.    Permission is granted to copy and distribute modified versions of
  15. this manual under the conditions for verbatim copying, provided also
  16. that the entire resulting derived work is distributed under the terms
  17. of a permission notice identical to this one.
  18.    Permission is granted to copy and distribute translations of this
  19. manual into another language, under the above conditions for modified
  20. versions.
  21. File: iostream.info,  Node: Formatting,  Next: Stdiobuf,  Prev: Overflow,  Up: Streambuf
  22. C-style formatting for `streambuf' objects
  23. ==========================================
  24.    The GNU `streambuf' class supports `printf'-like formatting and
  25. scanning.
  26.  - Method: int streambuf::vform (const char *FORMAT, ...)
  27.      Similar to `fprintf(FILE, FORMAT, ...)'.  The FORMAT is a
  28.      `printf'-style format control string, which is used to format the
  29.      (variable number of) arguments, printing the result on the `this'
  30.      streambuf.  The result is the number of characters printed.
  31.  - Method: int streambuf::vform (const char *FORMAT, va_list ARGS)
  32.      Similar to `vfprintf(FILE, FORMAT, ARGS)'.  The FORMAT is a
  33.      `printf'-style format control string, which is used to format the
  34.      argument list ARGS, printing the result on the `this' streambuf.
  35.      The result is the number of characters printed.
  36.  - Method: int streambuf::scan (const char *FORMAT, ...)
  37.      Similar to `fscanf(FILE, FORMAT, ...)'.  The FORMAT is a
  38.      `scanf'-style format control string, which is used to read the
  39.      (variable number of) arguments from the `this' streambuf.  The
  40.      result is the number of items assigned, or `EOF' in case of input
  41.      failure before any conversion.
  42.  - Method: int streambuf::vscan (const char *FORMAT, va_list ARGS)
  43.      Like `streambuf::scan', but takes a single `va_list' argument.
  44. File: iostream.info,  Node: Stdiobuf,  Next: Procbuf,  Prev: Formatting,  Up: Streambuf
  45. Wrappers for C `stdio'
  46. ======================
  47.    A "stdiobuf" is a `streambuf' object that points to a `FILE' object
  48. (as defined by `stdio.h').  All `streambuf' operations on the
  49. `stdiobuf' are forwarded to the `FILE'.  Thus the `stdiobuf' object
  50. provides a wrapper around a `FILE', allowing use of `streambuf'
  51. operations on a `FILE'.  This can be useful when mixing C code with C++
  52. code.
  53.    The pre-defined streams `cin', `cout', and `cerr' are normally
  54. implemented as `stdiobuf' objects that point to respectively `stdin',
  55. `stdout', and `stderr'.  This is convenient, but it does cost some
  56. extra overhead.
  57.    If you set things up to use the implementation of `stdio' provided
  58. with this library, then `cin', `cout', and `cerr' will be set up to to
  59. use `stdiobuf' objects, since you get their benefits for free.  *Note C
  60. Input and Output: Stdio.
  61. File: iostream.info,  Node: Procbuf,  Next: Backing Up,  Prev: Stdiobuf,  Up: Streambuf
  62. Reading/writing from/to a pipe
  63. ==============================
  64.    The "procbuf" class is a GNU extension.  It is derived from
  65. `streambuf'.  A `procbuf' can be "closed" (in which case it does
  66. nothing), or "open" (in which case it allows communicating through a
  67. pipe with some other program).
  68.  - Constructor:  procbuf::procbuf ()
  69.      Creates a `procbuf' in a "closed" state.
  70.  - Method: procbuf* procbuf::open (const char *COMMAND, int MODE)
  71.      Uses the shell (`/bin/sh') to run a program specified by COMMAND.
  72.      If MODE is `ios::in', standard output from the program is sent to
  73.      a pipe; you can read from the pipe by reading from the `procbuf'.
  74.      (This is similar to `popen(COMMAND, "r")'.)
  75.      If MODE is `ios::out', output written written to the `procbuf' is
  76.      written to a pipe; the program is set up to read its standard
  77.      input from (the other end of) the pipe.  (This is similar to
  78.      `popen(COMMAND, "w")'.)
  79.      The `procbuf' must start out in the "closed" state.  Returns
  80.      `*this' on success, and `NULL' on failure.
  81.  - Constructor:  procbuf::procbuf (const char *COMMAND, int MODE)
  82.      Calls `procbuf::open (COMMAND, MODE)'.
  83.  - Method: procbuf* procbuf::close ()
  84.      Waits for the program to finish executing, and then cleans up the
  85.      resources used.  Returns `*this' on success, and `NULL' on failure.
  86.  - Destructor:  procbuf::~procbuf ()
  87.      Calls `procbuf::close'.
  88. File: iostream.info,  Node: Backing Up,  Next: Indirectbuf,  Prev: Procbuf,  Up: Streambuf
  89. Backing up
  90. ==========
  91.    The GNU iostream library allows you to ask a `streambuf' to remember
  92. the current position.  This allows you to go back to this position
  93. later, after reading further.  You can back up arbitrary amounts, even
  94. on unbuffered files or multiple buffers' worth, as long as you tell the
  95. library in advance.  This unbounded backup is very useful for scanning
  96. and parsing applications.  This example shows a typical scenario:
  97.      // Read either "dog", "hound", or "hounddog".
  98.      // If "dog" is found, return 1.
  99.      // If "hound" is found, return 2.
  100.      // If "hounddog" is found, return 3.
  101.      // If none of these are found, return -1.
  102.      int my_scan(streambuf* sb)
  103.      {
  104.          streammarker fence(sb);
  105.          char buffer[20];
  106.          // Try reading "hounddog":
  107.          if (sb->sgetn(buffer, 8) == 8
  108.              && strncmp(buffer, "hounddog", 8) == 0)
  109.            return 3;
  110.          // No, no "hounddog":  Back up to 'fence'
  111.          sb->seekmark(fence); //
  112.          // ... and try reading "dog":
  113.          if (sb->sgetn(buffer, 3) == 3
  114.              && strncmp(buffer, "dog", 3) == 0)
  115.            return 1;
  116.          // No, no "dog" either:  Back up to 'fence'
  117.          sb->seekmark(fence); //
  118.          // ... and try reading "hound":
  119.          if (sb->sgetn(buffer, 5) == 5
  120.              && strncmp(buffer, "hound", 5) == 0)
  121.            return 2;
  122.          // No, no "hound" either:  Back up and signal failure.
  123.          sb->seekmark(fence); // Backup to 'fence'
  124.          return -1;
  125.      }
  126.  - Constructor:  streammarker::streammarker (streambuf* SBUF)
  127.      Create a `streammarker' associated with SBUF that remembers the
  128.      current position of the get pointer.
  129.  - Method: int streammarker::delta (streammarker& MARK2)
  130.      Return the difference between the get positions corresponding to
  131.      `*this' and MARK2 (which must point into the same `streambuffer'
  132.      as `this').
  133.  - Method: int streammarker::delta ()
  134.      Return the position relative to the streambuffer's current get
  135.      position.
  136.  - Method: int streambuf::seekmark (streammarker& MARK)
  137.      Move the get pointer to where it (logically) was when MARK was
  138.      constructed.
  139. File: iostream.info,  Node: Indirectbuf,  Prev: Backing Up,  Up: Streambuf
  140. Forwarding I/O activity
  141. =======================
  142.    An "indirectbuf" is one that forwards all of its I/O requests to
  143. another streambuf.
  144.    An `indirectbuf' can be used to implement Common Lisp
  145. synonym-streams and two-way-streams:
  146.      class synonymbuf : public indirectbuf {
  147.         Symbol *sym;
  148.         synonymbuf(Symbol *s) { sym = s; }
  149.         virtual streambuf *lookup_stream(int mode) {
  150.             return coerce_to_streambuf(lookup_value(sym)); }
  151.      };
  152. File: iostream.info,  Node: Stdio,  Next: Index,  Prev: Streambuf,  Up: Top
  153. C Input and Output
  154. ******************
  155.    `libio' is distributed with a complete implementation of the ANSI C
  156. `stdio' facility.  It is implemented using `streambuf' objects.  *Note
  157. Wrappers for C `stdio': Stdiobuf.
  158.    The `stdio' package is intended as a replacement for the whatever
  159. `stdio' is in your C library.  Since `stdio' works best when you build
  160. `libc' to contain it, and that may be inconvenient, it is not installed
  161. by default.
  162.    Extensions beyond ANSI:
  163.    * A stdio `FILE' is identical to a streambuf.  Hence there is no
  164.      need to worry about synchronizing C and C++ input/output--they are
  165.      by definition always synchronized.
  166.    * If you create a new streambuf sub-class (in C++), you can use it
  167.      as a `FILE' from C.  Thus the system is extensible using the
  168.      standard `streambuf' protocol.
  169.    * You can arbitrarily mix reading and writing, without having to seek
  170.      in between.
  171.    * Unbounded `ungetc()' buffer.
  172. File: iostream.info,  Node: Index,  Prev: Stdio,  Up: Top
  173. Index
  174. *****
  175. * Menu:
  176. * (:                                    States.
  177. * (:                                    States.
  178. * << on ostream:                        Operators.
  179. * >> on istream:                        Operators.
  180. * iostream destructor:                  Iostream.
  181. * badbit:                               States.
  182. * beg:                                  Output Position.
  183. * cerr:                                 Operators.
  184. * cin:                                  Operators.
  185. * class fstreambase:                    Files.
  186. * class fstream:                        Files.
  187. * class ifstream:                       Files.
  188. * class istrstream:                     Strings.
  189. * class ostream:                        Files.
  190. * class ostrstream:                     Strings.
  191. * class strstreambase:                  Strings.
  192. * class strstreambuf:                   Strings.
  193. * class strstream:                      Strings.
  194. * cout:                                 Operators.
  195. * cur:                                  Output Position.
  196. * dec:                                  Manipulators.
  197. * destructor for iostream:              Iostream.
  198. * end:                                  Output Position.
  199. * endl:                                 Manipulators.
  200. * ends:                                 Manipulators.
  201. * eofbit:                               States.
  202. * failbit:                              States.
  203. * flush:                                Ostream Housekeeping.
  204. * flush:                                Manipulators.
  205. * fstream:                              Files.
  206. * fstreambase:                          Files.
  207. * fstreambase::close:                   Files.
  208. * get area:                             Areas.
  209. * goodbit:                              States.
  210. * hex:                                  Manipulators.
  211. * ifstream:                             Files and Strings.
  212. * ifstream:                             Files.
  213. * ifstream::ifstream:                   Files.
  214. * ifstream::ifstream:                   Files.
  215. * ifstream::ifstream:                   Files.
  216. * ifstream::open:                       Files.
  217. * ios::app:                             Files.
  218. * ios::ate:                             Files.
  219. * ios::bad:                             States.
  220. * ios::beg:                             Input Position.
  221. * ios::bin:                             Files.
  222. * ios::bitalloc:                        Extending.
  223. * ios::clear:                           States.
  224. * ios::cur:                             Input Position.
  225. * ios::dec:                             Format Control.
  226. * ios::end:                             Input Position.
  227. * ios::eof:                             States.
  228. * ios::fail:                            States.
  229. * ios::fill:                            Format Control.
  230. * ios::fill:                            Format Control.
  231. * ios::fixed:                           Format Control.
  232. * ios::flags:                           Format Control.
  233. * ios::flags:                           Format Control.
  234. * ios::good:                            States.
  235. * ios::hex:                             Format Control.
  236. * ios::in:                              Files.
  237. * ios::internal:                        Format Control.
  238. * ios::ios:                             Ios.
  239. * ios::iword:                           Extending.
  240. * ios::iword:                           Extending.
  241. * ios::left:                            Format Control.
  242. * ios::nocreate:                        Files.
  243. * ios::noreplace:                       Files.
  244. * ios::oct:                             Format Control.
  245. * ios::out:                             Files.
  246. * ios::precision:                       Format Control.
  247. * ios::precision:                       Format Control.
  248. * ios::pword:                           Extending.
  249. * ios::pword:                           Extending.
  250. * ios::rdbuf:                           Streambuf from Ios.
  251. * ios::rdstate:                         States.
  252. * ios::right:                           Format Control.
  253. * ios::scientific:                      Format Control.
  254. * ios::seekdir:                         Output Position.
  255. * ios::set:                             States.
  256. * ios::setf:                            Format Control.
  257. * ios::setf:                            Format Control.
  258. * ios::setstate:                        States.
  259. * ios::showbase:                        Format Control.
  260. * ios::showpoint:                       Format Control.
  261. * ios::showpos:                         Format Control.
  262. * ios::skipws:                          Format Control.
  263. * ios::stdio:                           Format Control.
  264. * ios::sync_with_stdio:                 Synchronization.
  265. * ios::tie:                             Synchronization.
  266. * ios::tie:                             Synchronization.
  267. * ios::trunc:                           Files.
  268. * ios::unitbuf:                         Format Control.
  269. * ios::unsetf:                          Format Control.
  270. * ios::uppercase:                       Format Control.
  271. * ios::width:                           Format Control.
  272. * ios::width:                           Format Control.
  273. * ios::xalloc:                          Extending.
  274. * ios::~ios:                            Ios.
  275. * iostream::iostream:                   Iostream.
  276. * iostream::iostream:                   Iostream.
  277. * istream::gcount:                      Istream Housekeeping.
  278. * istream::get:                         Char Input.
  279. * istream::get:                         Char Input.
  280. * istream::get:                         String Input.
  281. * istream::get:                         String Input.
  282. * istream::getline:                     String Input.
  283. * istream::gets:                        String Input.
  284. * istream::ignore:                      Istream Housekeeping.
  285. * istream::ipfx:                        Istream Housekeeping.
  286. * istream::isfx:                        Istream Housekeeping.
  287. * istream::istream:                     Istream.
  288. * istream::istream:                     Istream.
  289. * istream::peek:                        Char Input.
  290. * istream::putback:                     Istream Housekeeping.
  291. * istream::read:                        String Input.
  292. * istream::scan:                        String Input.
  293. * istream::seekg:                       Input Position.
  294. * istream::seekg:                       Input Position.
  295. * istream::tellg:                       Input Position.
  296. * istream::unget:                       Istream Housekeeping.
  297. * istream::vscan:                       String Input.
  298. * istrstream:                           Strings.
  299. * istrstream:                           Files and Strings.
  300. * istrstream::istrstream:               Strings.
  301. * oct:                                  Manipulators.
  302. * ofstream:                             Files and Strings.
  303. * ofstream::ofstream:                   Files.
  304. * ofstream::ofstream:                   Files.
  305. * ofstream::ofstream:                   Files.
  306. * ofstream::open:                       Files.
  307. * ofstream::~ofstream:                  Files.
  308. * ostream:                              Files.
  309. * ostream::form:                        Writing.
  310. * ostream::opfx:                        Ostream Housekeeping.
  311. * ostream::osfx:                        Ostream Housekeeping.
  312. * ostream::ostream:                     Ostream.
  313. * ostream::ostream:                     Ostream.
  314. * ostream::put:                         Writing.
  315. * ostream::seekp:                       Output Position.
  316. * ostream::seekp:                       Output Position.
  317. * ostream::tellp:                       Output Position.
  318. * ostream::vform:                       Writing.
  319. * ostream::write:                       Writing.
  320. * ostrstream:                           Strings.
  321. * ostrstream:                           Files and Strings.
  322. * ostrstream::freeze:                   Strings.
  323. * ostrstream::frozen:                   Strings.
  324. * ostrstream::ostrstream:               Strings.
  325. * ostrstream::ostrstream:               Strings.
  326. * ostrstream::pcount:                   Strings.
  327. * ostrstream::str:                      Strings.
  328. * procbuf::close:                       Procbuf.
  329. * procbuf::open:                        Procbuf.
  330. * procbuf::procbuf:                     Procbuf.
  331. * procbuf::procbuf:                     Procbuf.
  332. * procbuf::~procbuf:                    Procbuf.
  333. * put area:                             Areas.
  334. * setbase:                              Manipulators.
  335. * setfill:                              Manipulators.
  336. * setprecision:                         Format Control.
  337. * setprecision:                         Manipulators.
  338. * setting ios::precision:               Format Control.
  339. * setting ios::width:                   Format Control.
  340. * setw:                                 Format Control.
  341. * setw:                                 Manipulators.
  342. * streambuf::eback:                     Areas.
  343. * streambuf::egptr:                     Areas.
  344. * streambuf::epptr:                     Areas.
  345. * streambuf::gptr:                      Areas.
  346. * streambuf::pbase:                     Areas.
  347. * streambuf::pbump:                     Areas.
  348. * streambuf::pptr:                      Areas.
  349. * streambuf::scan:                      Formatting.
  350. * streambuf::seekmark:                  Backing Up.
  351. * streambuf::setg:                      Areas.
  352. * streambuf::setp:                      Areas.
  353. * streambuf::vform:                     Formatting.
  354. * streambuf::vform:                     Formatting.
  355. * streambuf::vscan:                     Formatting.
  356. * streambuf:gbump:                      Areas.
  357. * streammarker::delta:                  Backing Up.
  358. * streammarker::delta:                  Backing Up.
  359. * streammarker::streammarker:           Backing Up.
  360. * strstream:                            Strings.
  361. * strstreambase:                        Strings.
  362. * strstreambase::rdbuf:                 Strings.
  363. * strstreambuf:                         Strings.
  364. * ws:                                   Manipulators.
  365.